#include <aphw/Key.hpp>

#include <strings.h>

#include <boost/python.hpp>

using namespace boost::python;

namespace aphw
{

Key::Key() {
    init();
}

Key::Key(unsigned long v) :
    key_value_ (v) {
    init();
}

void Key::init() {
    bzero(&key_, sizeof(key_));
    key_.size = sizeof(key_value_);
    key_.data = &key_value_;
    key_.flags |= HAM_KEY_USER_ALLOC;
}    

unsigned int Key::value() const
{
    return key_value_;
}

int Key::approximateMatchType() const {
    return ham_key_get_approximate_match_type(
        &(const_cast<Key*>(this)->key_));
}

ham_key_t* Key::key()
{
    return &key_;
}

void init_Key()
{
    class_<Key>("Key", init<>())
        .def(init<unsigned long>())
        .add_property("value", &Key::value)
        .add_property("approximate_match_type", &Key::approximateMatchType)
        ;
}

}
